<?php
	require("connect.php");
	if (isset($_REQUEST['taikhoan']) && isset($_REQUEST['matkhau'])) {
		$tk = $_REQUEST['taikhoan'];
		$pw = md5($_REQUEST['matkhau']);
		if (strpos(" ".$tk,"QL") == 1) {
			$result = $mysqli->query("select MA_NVQL as TK,PW_NVQL as PW from nvquanly where MA_NVQL = '{$tk}'");
		} elseif (strpos(" ".$tk,"GV") == 1) {
			$result = $mysqli->query("select MA_GV as TK,PW_GV as PW from giaovien where MA_GV = '{$tk}'");
		} elseif (strpos(" ".$tk,"PH") == 1) {
			$result = $mysqli->query("select MA_PH as TK,PW_PH as PW from phuhuynh where MA_PH = '{$tk}'");
		} else echo "e1";
		if ($result->num_rows == 0) {
			echo "e1";
		} else {
			$row = $result->fetch_array();
			if($pw != $row['PW']) {
				echo "e2";
			} else {
				$_SESSION['taikhoan'] = $row['TK'];
				if (strpos(" ".$tk,"QL") == 1)
					echo "<meta http-equiv='Refresh' content='0;url=quanly/index.php?session=".$_SESSION['taikhoan']."'>";
				elseif (strpos(" ".$tk,"GV") == 1)
					echo "<meta http-equiv='Refresh' content='0;url=giaovien/index.php?session=".$_SESSION['taikhoan']."'>";
				elseif (strpos(" ".$tk,"PH") == 1)
					echo "<meta http-equiv='Refresh' content='0;url=phuhuynh/index.php?session=".$_SESSION['taikhoan']."'>";
			}
		}
	}
	$mysqli->close();
?>